package com.sooth.system.post.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.dream.system.config.Page;
import com.sooth.common.core.domain.R;
import com.sooth.common.dream.model.PageModel;
import com.sooth.common.log.annotation.Log;
import com.sooth.common.web.core.BaseController;
import com.sooth.system.post.service.ISysPostService;
import com.sooth.system.post.view.SysPostBo;
import com.sooth.system.post.view.SysPostDto;
import com.sooth.system.post.view.SysPostVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 岗位信息操作处理
 *
 * @author Lion Li
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/post")
public class SysPostController extends BaseController {

    private final ISysPostService postService;

    /**
     * 获取岗位列表
     */
    @SaCheckPermission("system:post:query")
    @GetMapping("/list")
    public R<Page<SysPostVo>> list(SysPostDto post, PageModel pageModel) {
        return R.ok(postService.selectPage(post, pageModel));
    }

    /**
     * 不分页获取岗位列表
     */
    @SaCheckPermission("system:post:query")
    @GetMapping("/listAll")
    public R<List<SysPostVo>> listAll(SysPostDto post) {
        return R.ok(postService.selectList(post));
    }

    /**
     * 根据岗位编号获取详细信息
     *
     * @param id 岗位ID
     */
    @SaCheckPermission("system:post:query")
    @GetMapping(value = "/query")
    public R<SysPostBo> query(@RequestParam Long id) {
        return R.ok(postService.selectById(id));
    }

    /**
     * 新增岗位
     */
    @SaCheckPermission("system:post:add")
    @Log(title = "岗位管理", message = "新增岗位")
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysPostBo post) {
        return toAjax(postService.insert(post));
    }

    /**
     * 修改岗位
     */
    @SaCheckPermission("system:post:edit")
    @Log(title = "岗位管理", message = "修改岗位")
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody SysPostBo post) {
        return toAjax(postService.updateById(post));
    }

    /**
     * 删除岗位
     *
     * @param id 岗位ID
     */
    @SaCheckPermission("system:post:remove")
    @Log(title = "岗位管理", message = "删除岗位")
    @DeleteMapping("/remove")
    public R<Void> remove(@RequestParam Long id) {
        return toAjax(postService.deleteById(id));
    }
}
